home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / kriegspi / xboard.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-06-30  |  3.5 KB  |  161 lines

  1. #ifndef lint
  2. static char rcsid[] = "$Header: xboard.c,v 1.6 87/05/19 17:21:01 schoch Exp $";
  3. #endif
  4.  
  5. #include "externs.h"
  6.  
  7. static deltax, deltay;
  8. static    Pixmap shadow;
  9. static    int frompos;
  10. static    bool realmove;
  11.  
  12. startmove(pos, x, y)
  13. {
  14.  
  15.     if (pos < 0)
  16.     return;
  17.     if (pos >= 100) {
  18.     fprintf(stderr, "Help!  pos out of range.\n");
  19.     return;
  20.     }
  21.     if (dead || resign || (drawok[BLACK] && drawok[WHITE])) {
  22.     message("The game is over!", TOMOVE);
  23.     return;
  24.     }
  25.     if (whose[pos] == OFFBOARD) {
  26.     int myx;
  27.  
  28.     if (ourcolor == WHITE && (y < 64*8+TOPSPACE || y > 64*8+TOPSPACE+64))
  29.         return;
  30.     if (ourcolor == BLACK && !reverse &&
  31.         (y < TOPSPACE-64 || y > TOPSPACE))
  32.         return;
  33.     if (ourcolor == BLACK && reverse &&
  34.         (y < 64*8+TOPSPACE || y > 64*8+TOPSPACE+64))
  35.         return;
  36.     if (x < 0 || x > 8*64)
  37.         return;
  38.     myx = x - 16;
  39.     if (myx < 0)
  40.         pos = 0;
  41.     else
  42.         pos = myx / 32;
  43.     pos += (ourcolor == WHITE) ? 16 : 0;
  44.     if (captured[pos] == 0) {
  45.         if (myx % 32 < 16)
  46.         pos--;
  47.         else
  48.         pos++;
  49.         if (pos < 0)
  50.         return;
  51.         if (captured[pos] == 0)
  52.         return;
  53.     }
  54.     move = 1;
  55.     deltax = x - (pos%16)*32;
  56.     deltay = y-TOPSPACE;
  57.     if (ourcolor == WHITE || reverse)
  58.         deltay -= 64*8;
  59.     else
  60.         deltay += 64;
  61.     shadow = pieces_icons[captured[pos]];
  62.     frompos = -pos;
  63.     realmove = FALSE;
  64.     goto done;
  65.     }
  66.     if ((occupant[pos] == 0 || whose[pos] == theircolor) && ghost[pos] == 0)
  67.     return;
  68.     if (whose[pos] == ourcolor) {
  69.     if (color != ourcolor) {
  70.         message("It's not your turn!", TOMOVE);
  71.         return;
  72.     } else if (drawok[theircolor]) {
  73.         message("Respond with 'y' or 'n'", TOMOVE);
  74.         return;
  75.     } else
  76.         realmove = TRUE;
  77.     } else
  78.     realmove = FALSE;        /* ghost */
  79.     move = 1;
  80.     frompos = pos;
  81.     if (reverse) {
  82.     deltax = x - (8-pos%10)*64;
  83.     deltay = y-TOPSPACE - (8-pos/10)*64;
  84.     } else {
  85.     deltax = x - (pos%10-1)*64;
  86.     deltay = y-TOPSPACE - (pos/10-1)*64;
  87.     }
  88.     /* Do sanity checking here! */
  89.     if (ghost[pos])
  90.     shadow = pieces_icons[ghost[pos]];
  91.     else
  92.     shadow = pieces_icons[occupant[pos]];
  93. done:
  94.     XPixmapPut(window, 0, 0, x-deltax, y-deltay, 64, 64, shadow, GXxor, 1);
  95. }
  96.  
  97. stopmove(pos, x, y)
  98. {
  99.     bool *arr;
  100.     int ox, oy;
  101.  
  102.     if (move == 0)
  103.     return;
  104.     move = 0;
  105.     /* Remove shadow */
  106.     XPixmapPut(window, 0, 0, x - deltax, y - deltay, 64, 64, shadow, GXxor, 1);
  107.  
  108.     if (pos < 0)    /* out of window */
  109.     return;
  110.     if (pos == frompos)
  111.     return;        /* didn't move anywhere */
  112.  
  113.     /* Check if opponent resigned while we were in the process of moving. */
  114.     if (dead || resign || (drawok[BLACK] && drawok[WHITE]))
  115.     return;
  116.     if (realmove == FALSE) {        /* move a ghost */
  117.     if (frompos <= 0) {
  118.         frompos = -frompos;
  119.         arr = captured;
  120.         if (whose[pos] == OFFBOARD)
  121.         return;        /* it didn't go anywhere */
  122.     } else
  123.         arr = ghost;
  124.     if (whose[pos] == ourcolor || ghost[pos])
  125.         return;            /* A ghost can't capture. */
  126.     if (arr == ghost)
  127.         redraw_pos(frompos);
  128.     else {
  129.         ox = (frompos % 16) * 32;
  130.         if (reverse)
  131.         oy = TOPSPACE + ((frompos>15) ? -64 : 64*8);
  132.         else
  133.         oy = TOPSPACE + ((frompos>15) ? 64*8 : -64);
  134.         XPixmapPut(window, 0, 0, ox, oy, 64, 64, shadow, GXandInverted, 1);
  135.     }
  136.     if (whose[pos] == OFFBOARD) {
  137.         ghost_capture(frompos);
  138.         ghost[frompos] = 0;
  139.         return;
  140.     }
  141.     ghost[pos] = arr[frompos];
  142.     arr[frompos] = 0;
  143.     redraw_ghost(pos);
  144.     return;
  145.     }
  146.     if (whose[pos] == OFFBOARD) {
  147.     return;
  148.     }
  149.     domove(frompos, pos);
  150.  
  151. }
  152.  
  153. piecemove(oldx, oldy, x, y)
  154. {
  155.  
  156.     XPixmapPut(window, 0, 0, oldx-deltax,oldy-deltay,
  157.     64, 64, shadow, GXxor, 1);
  158.     XPixmapPut(window, 0, 0, x - deltax, y - deltay,
  159.     64, 64, shadow, GXxor, 1);
  160. }
  161.